package com.atguigu.spzx.cloud.order.service.impl;

import com.atguigu.spzx.cloud.api.client.UserFeignClient;
import com.atguigu.spzx.cloud.model.entity.Order;
import com.atguigu.spzx.cloud.model.entity.User;


import com.atguigu.spzx.cloud.order.mapper.OrderMapper;

import com.atguigu.spzx.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author ChenXing
 * @Description
 * @Create 2024/7/22 17:04
 */

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public Order findOrderByOrderId(Long orderId) {
        Order order = orderMapper.selectOrderByOrderId(orderId);
      //  User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + order.getUserId(), User.class);
        User user = userFeignClient.findUserById(order.getUserId());
        order.setUser(user);
        return order;
    }

    @Override
    public List<Order> findOrderListByUserId(Long userId) {
        List<Order> orderList =  orderMapper.selectOrderListByUserId(userId);
        return orderList;
    }
}
